<?php

namespace App\Exports;

use App\Models\Client;
use App\Models\Department;
use Carbon\Carbon;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use App\Models\User;
use App\Models\CrmConfig;

class MoneyOutExport extends ExcelExporter implements WithMapping, WithHeadings, ShouldAutoSize
{

    //这里是导出来的文件的名字和格式
    protected $fileName = '贷款列表.xlsx';
    //这里是excel的标题
    public function headings(): array
    {
        return [
            '签约日期',
            '姓名',
            '电话',
            '所属销售员',
            '上级主管',
            '所属三级部门',
            '所属二级部门',
            '所属一级部门',
            '权证跟进状态',
            '最新跟进记录',
            '最新跟进时间',
            '未跟进天数',
            '权证人',
        ];
    }

    public function map($model): array
    {
        $l3 = Department::getLevel(3);
        $l2 = Department::getLevel(2);
        $l1 = Department::getLevel(1);
        $users = User::Users();
        $list = [
            $model->employee->dep_l3,
            $model->employee->dep_l2,
            $model->employee->dep_l1,
            $model->status,
            $model->employee_status,
            $model->employee_id,
        ];
        $client_status[0] = $follow_status[0] = $l1[0] = $l2[0] = $l3[0] = $users[0] = $records = $last_updated_at = $nt = '';
        foreach ($list as $key => $item){
            if(empty($item)){
                $list[$key] = 0;
            }
        }
        return [
            $model->created_at,
            $model->name,
            User::Users()[$model->employee_id],
            $model->out_id,
            $model->out_money,
            $model->fee,
            $model->pay_type,
            $model->pay_monthly,
            $model->pay_count,
            $model->out_at,
        ];
    }



}
